package com.yanqu.road.server.cmd.activity.apprentice;

import com.yanqu.road.exception.BusinessException;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ApprenticeProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.apprentice.ApprenticeModule;
import com.yanqu.road.server.protocol.Protocol;

@CmdApi(reqMsg = ApprenticeProto.ApprenticeDoProjectReqMsg.class, respMsg = ApprenticeProto.ApprenticeDoProjectRespMsg.class)
@Cmd(code = Protocol.S_APPRENTICE_DO_PROJECT,desc = "爱徒养成-执行项目")
public class ApprenticeDoProjectCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ApprenticeProto.ApprenticeDoProjectReqMsg reqMsg = ApprenticeProto.ApprenticeDoProjectReqMsg.parseFrom(packet.getBytes());
        ApprenticeProto.ApprenticeDoProjectRespMsg.Builder respMsg = ApprenticeProto.ApprenticeDoProjectRespMsg.newBuilder();
        try {
            //执行项目
            player.getModule(ApprenticeModule.class).doProjects(reqMsg);
        } catch (BusinessException e) {
            respMsg.setRet(e.getCode());
            player.sendPacket(Protocol.U_APPRENTICE_DO_PROJECT, respMsg);
        }
    }

    @Override
    public void sendData(GamePlayer player) {}
}
